import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class TestMyLinkedList {
    public static void main(String[] args) {
        LinkedList<Integer> list=new LinkedList<>();
        list.add(15);
        list.add(25);
        list.add(35);
        list.add(45);
        list.add(55);
        //1.通过System.out.println(list);将其遍历
        System.out.println(list);
        System.out.println("=================");
        //2.通过for循环将其遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("=================");
        //3.通过foreach将其遍历
        for (Integer x : list){
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("=================");
        //4.通过Iterator迭代器将其遍历
        Iterator<Integer> it=list.iterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("=================");
        //5.通过listIterator将其遍历
       ListIterator<Integer> it2=list.listIterator();
        while (it2.hasNext()){
            System.out.print(it2.next()+" ");
        }
        System.out.println();
        System.out.println("=================");
        //6.从给定的下标处开始遍历
        ListIterator<Integer> it3=list.listIterator(1);
        while (it3.hasNext()){
            System.out.print(it3.next()+" ");
        }
        System.out.println();
        System.out.println("=================");
        //7.反向遍历
        ListIterator<Integer> it4=list.listIterator(list.size());
        while (it4.hasPrevious()){
            System.out.print(it4.previous()+" ");
        }
        System.out.println();
        System.out.println("=================");
    }
}
